<template>
	<view class="myDirect">
		<view class="wallet_amount">
			<view class="wallet_amount_num">
				<view class="wallet_amount_num_fir my-pdl-15">
					<view class="wallet_amount_num_fir_txt my-pdt-10">直营总数(个)</view>
					<view class="wallet_amount_num_fir_jine">{{ directCount || 0 }}</view>
				</view>
				<view class="wallet_amount_num_two">
					<view class="tady my-pdl-15">
						<view class="fir_box">本月新增（个）</view>
						<view class="two_box">{{monthAdd || 0}}</view>
					</view>
					<view class="cumulative">
						<view class="fir_box">已激活（个）</view>
						<view class="two_box">{{activationCount || 0}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="direct-list my-mgt-30 my-mgb-30">
			<template v-if="dev.length > 0">
				<view class="direct-list__item my-mgt-15"  v-for="(item, index) in dev" :key="index" @click="goTranscationFlow(item)">
					<view class="item-top">
						<view class="item-name">姓名：{{item.bindMemberName}}</view>
						<view class="item-status" :class="item.activation?'active':'unactive'">{{item.activation ? '已激活' : '未激活'}}</view>
					</view>
					<view class="item-info">
						<view class="item-info__label">手机号：{{item.phone||'暂无'}}</view>
						<view class="item-info__label">商户号：{{item.businessNumber||'暂无'}}</view>
						<view class="item-info__label">设备号：{{item.deviceNo||'暂无'}}</view>
						<view class="item-info__label">绑定时间：{{item.bindDate||'暂无'}}</view>
						<view class="item-info__label">激活时间：{{item.activationDate||'暂无'}}</view>
					</view>
				</view>
			</template>
			<view style="height: 300rpx;line-height: 300rpx;text-align: center;" v-else>暂无数据</view>
		</view>
	</view>
</template>

<script>
	import { directCountApi, directListApi, directTranscationApi } from "@/api/direct.js"
	export default {
		data() {
			return {
				endDate:null,
				directCount: 0, // 直营总数
				activationCount: 0, // 已激活
				monthAdd: 0, // 本月新增
				pageIndex:0, // 页数
				pageSize:30, // 条数
				dev:[],
				total:1,
			};
		},
		onLoad() {
			this.myDirectCount()
			// this.gettotalData()
			this.getDrectList()
		},
		// created() {
		// 	this.getDate()
		// },
		// 上拉加载更多
		onReachBottom() {
			this.getDrectList()
		},
		methods:{
			// // 获取选中时间
			// onEnd(e) {
			// 	this.endDate = e.target.value
			// 	this.dev=[]
			// 	this.gettotalData()
			// 	this.getDrectList()
			// },
			// getDate() {
			// 	const date = new Date();
			// 	let year = date.getFullYear();
			// 	let month = date.getMonth() + 1;
			// 	month = month > 9 ? month : '0' + month;
			// 	this.endDate = `${year}-${month}`;
			// },
			// 获取汇总数据
			async myDirectCount() {
				uni.showLoading({
					title: "正在加载中...."
				})
				const res = await directCountApi()
				if(res.statusCode===200){
					uni.hideLoading()
					this.balance = res.data.data.directCount
					this.activationCount = res.data.data.activationCount
					this.monthAdd = res.data.data.monthAdd
				}
			},
			//获取列表信息
			async getDrectList(){
				if (this.dev.length >= this.total){
					uni.showToast({
						title:"没有更多数据了",
						icon:"none"
					})
					return
				}
				let params = {
					businessName: '',
					pageIndex: this.pageIndex,
					pageSize: this.pageSize
				}
				uni.showLoading({
					title: "正在加载中...."
				})
				const res = await directListApi(params)
				if(res.statusCode === 200){
					uni.hideLoading()
					this.dev = [...this.dev,...res.data.data.rows]
					this.total = res.data.data.total
					this.pageIndex++
				}
			},
			goTranscationFlow (item) {
				let id = item.id
				uni.navigateTo({
					url: `/pages/main/childPages/directTranscationFlow?id=${id}`,
					fail: (res) => {
						console.log(res)//打印错误信息
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.myDirect{
		width: 100%;
		min-height: 100vh;
		// background: #FAFAFA;
		.wallet_amount{
			width: 100%;
			background: #FFFFFF;
			.wallet_amount_num{
				width: 690rpx;
				height: 340rpx;
				margin: auto;
				background: linear-gradient(221deg, #C19C72 0%, #D5B28A 100%);
				box-shadow: 0rpx 18rpx 10rpx 0rpx rgba(193, 156, 114, 0.1);
				border-radius: 20rpx;
				.wallet_amount_num_fir{
					width: 100%;
					height: 170rpx;
					.wallet_amount_num_fir_txt,.wallet_amount_num_fir_jine{
						width: 100%;
						height: 50%;
						line-height: 85rpx;
						color: #FFFFFF;
					}
					.wallet_amount_num_fir_txt{
						font-size: 26rpx;
						font-weight: 500;
						
					}
					.wallet_amount_num_fir_jine{
						font-size: 60rpx;
						font-weight: bold;
					}
				}
				.wallet_amount_num_two{
					width: 100%;
					height: 170rpx;
					display: flex;
					align-items: center;
					.tady,.cumulative{
						width: 50%;
						height: 100%;
						.fir_box,.two_box{
							width: 100%;
							color: #FFFFFF;
						}
						.fir_box{
							height: 80rpx;
							line-height: 100rpx;
							font-size: 26rpx;
							font-weight: 500;
						}
						.two_box{
							height: 90rpx;
							font-size: 36rpx;
							font-weight: bold;
							
						}
					}
				}
			}
			.wallet_tab_box{
				width: 100%;
				height: 158rpx;
				display: flex;
				align-items: center;
				justify-content: space-around;
				.wallet_tab_box_bind{
					display: flex;
					align-items: center;
					font-size: 28rpx;
					font-weight: 500;
					color: #000000;
					image{
						width: 32rpx;
						height: 32rpx;
					}
				}
			}
		}
		.direct-list {
			padding:0 30rpx;
			
			&__item {
				background: #FFFFFF;
				box-shadow: 0 0 9rpx 1rpx rgba(0, 0, 0, 0.1);
				border-radius: 20rpx;
				.item-top {
					padding: 30rpx;
					position: relative;
					border-bottom: 1px solid #f2f2f2;
					.item-name {
						font-size: 26rpx;
						color: #333333;
						line-height: 1;
					}
					.item-status {
						position: absolute;
						font-size: 26rpx;
						line-height: 1;
						right: 30rpx;
						top: 30rpx;
						&.active {
							color: #22AB10;
						}
						&.unactive {
							color: #F05329;
						}
					}
				}
				.item-info {
					padding: 16rpx 29rpx;
					&__label {						
						font-size: 26rpx;
						color: #666666;
						line-height: 1;
						padding: 18rpx 0;
					}
				}
			}
		}
	}
</style>
